package com.swipemaster.dialogs;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.swipemaster.R;
import com.swipemaster.network.WorldRecord;

public class RecordsListAdapter extends BaseAdapter
{
	private final Context context;
	private final ArrayList<WorldRecord> records = new ArrayList<WorldRecord>();
	private int step = 10;
	private final int STEP_INCREASE = 2;

	public RecordsListAdapter(Context context)
	{
		this.context = context;
	}

	public void addRecords(List<WorldRecord> records)
	{
		this.records.addAll(records);
	}

	public void clear()
	{
		records.clear();
	}

	@Override
	public int getCount()
	{
		return records.size();
	}

	@Override
	public Object getItem(int pos)
	{
		return null;
	}

	@Override
	public long getItemId(int pos)
	{
		return 0;
	}

	public int getStep()
	{
		final int oldStep = step;
		step *= STEP_INCREASE;
		return oldStep;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		final View rowView = inflater.inflate(R.layout.high_score_table_row, parent, false);
		final TextView numberText = (TextView) rowView.findViewById(R.id.level_score_row_nr_textView);
		numberText.setText(Integer.toString(position + 1));

		final TextView usernameText = (TextView) rowView.findViewById(R.id.level_score_row_username);
		usernameText.setText(records.get(position).username);

		final TextView timeText = (TextView) rowView.findViewById(R.id.level_score_row_time);
		timeText.setText(records.get(position).toString());

		return rowView;
	}

}
